#include "mybar.h"


static lv_obj_t* label;
static lv_obj_t* bar;

//定义标签
static void lv_label(void)
{
    label = lv_label_create(lv_scr_act());
    lv_label_set_text(label, "0 %%");
    lv_obj_set_style_text_font(label, &lv_font_montserrat_20, LV_PART_MAIN);
    lv_obj_align(label, LV_ALIGN_CENTER,0,100);
}

static int val = 0;
static void timer_cb(lv_timer_t* timer)
{
    if(val < 100)
    {
        val++;
        lv_bar_set_value(bar, val, LV_ANIM_ON);
        lv_label_set_text_fmt(label, "%d %%",lv_bar_get_value(bar));
    }
    else
        lv_label_set_text(label, "finished!");
}

//定义进度条
static void lv_bar()
{
    bar = lv_bar_create(lv_scr_act());
    lv_obj_set_size(bar, 400, 20);
    lv_obj_set_align(bar,LV_ALIGN_CENTER);

    //定时器，每隔50ms进入一次timer_cb
    lv_timer_create(timer_cb, 50, NULL);
}

//主程序
static void bar_1(void)
{
    lv_label();
    lv_bar();
}


void mybar_example(void)
{
    bar_1();
}